package com.leetcode.array;

public class TwoSumII_InputArrayIsSorted {

	public static void main(String[] args) {
		int numarr[]={0,0,0,0,2,7,8,8,8,8,8};
        int target=9;
        int results[]=twoSum(numarr, target);
        System.out.println("{"+results[0]+","+results[1]+"}");
	}

    public static int[] twoSum(int[] numbers, int target) {
    	int len=numbers.length;
    	int results[]=new int[2];
//    	for(int i=0;i<len;i++){
//    		for(int j=i+1;j<len;j++){
//    			if(numbers[i]+numbers[j]==target){
//    				results[0]=i+1;
//    				results[1]=j+1;
//    			}
//    		}
//    	}

    	int i=0,j=len-1;
    	for(i=0,j=len-1;i<len&&j>i;){
    		if(numbers[i]+numbers[j]==target){
    			results[0]=i+1;
    			results[1]=j+1;
    			break;
    		}else{
    			if(numbers[i]+numbers[j]>target){
    				j--;
    			}else{
    				i++;
    			}
    		}
    	}
		return results;
    }
}
